package common;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;


import java.text.SimpleDateFormat;
import java.time.Duration;

public class Utils {
    //驱动
    protected static WebDriver driver = null;
    //显示等待
    protected static WebDriverWait wait = null;

    protected static WebElement element = null;

    public Utils(String URL) {
        driver = createDriver();
        driver.get(URL);
        //显示等待
        wait = new WebDriverWait(driver,Duration.ofSeconds(10));
    }

    private WebDriver createDriver() {
        if(driver == null) {
            WebDriverManager.edgedriver().setup();
            EdgeOptions options = new EdgeOptions();
            options.addArguments("--remote-allow-origins=*");
            //完全不阻塞WebDriver
//            options.setPageLoadStrategy(PageLoadStrategy.NONE);
            driver = new EdgeDriver(options);
            //隐式等待
            driver.manage().timeouts().implicitlyWait(Duration.ofMillis(10));
        }
        return driver;
    }


    public static void quit() {
        driver.quit();
    }
}
